<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <div id="app">
        <a href="#/zhuye">主页</a>
        <a href="#/keji">科技</a>
        <a href="#/caijing">财经</a>
        <a href="#/yule">娱乐</a>

        <component :is="comName"></component>
    </div>
    <script src="../js/vue.js"></script>
    <script>
        //定义要被切换的四个组件
        const zhuye = {
            template: `<h1>主页信息</h1> `
        }
        //科技组件
        const keji = {
            template: `<h1>科技信息</h1>`
        }
        //财经组件
        const caijing = {
            template: `<h1>财经信息</h1>`
        }
        //娱乐组件
        const yule = {
            template: `<h1>娱乐信息</h1>`
        }

        var vm = new Vue({
            el: '#app',
            data: {
                comName: 'zhuye'
            },
            //注册私有组件
            components: {
                'zhuye': zhuye,
                'keji': keji,
                'caijing': caijing,
                'yule': yule
            }
        })

        window.onhashchange = function () {
            switch (
                location.hash.slice(1)
            ) {
                case '/zhuye':
                    vm.comName = 'zhuye'
                    break;
                case '/keji':
                    vm.comName = 'keji'
                    break;
                case '/caijing':
                    vm.comName = 'caijing'
                    break;
                case '/yule':
                    vm.comName = 'yule'
                    break;
                default:
                    break;
            }
        }
    </script>
</body>

</html>